package com.nky.mapper;

import cn.hutool.json.JSONObject;
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.nky.pojo.Files;
import org.apache.ibatis.annotations.Select;

public interface FilesMapper extends BaseMapper<Files> {
    @Select("SELECT DISTINCT SUBSTRING_INDEX(object_key, '/', 1) AS name\n" +
            "FROM files")
    Page<JSONObject> getRootPath(Page<Files> page);

    @Select("SELECT DISTINCT SUBSTRING_INDEX(SUBSTRING_INDEX(object_key, '/', ${pathLevel}), '/', -1) AS name\n" +
            "FROM files WHERE object_key LIKE '${filePath}'")
    Page<JSONObject> getFilesByPath(Page<Files> page,int pathLevel, String filePath);
}
